<template>
  <div class="login">
    <input type="text" placeholder="请输入手机号" v-model="username">
    <input type="text" placeholder="请输入密码" v-model="password">
    <button @click="login">登录</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username:'',
      password:''
    }
  },
  methods: {
    login(){
      uni.request({
        url: 'http://10.31.71.56:7001/api/login',
        data: {
          username:this.username,
          password:this.password
        },
        method: 'POST',
        success: (res) => {
          console.log(res);
          if(res.statusCode===200){
            uni.setStorageSync('token', res.data.token);
            uni.setStorageSync('name', res.data.user.name);
            uni.setStorageSync('img', res.data.user.user_img);
            uni.setStorageSync('username',res.data.user.username);
            uni.navigateBack({ delta: -1 })
          }
        },
      })
    }
  },
}
</script>

<style scoped lang='scss'>
.login{
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  input{
    width: 90vw;
    height: 50px;
    margin-left: 5vw;
    border: solid 1px #ccc;
    margin: 5px 0;
    border-radius: 10px;
  }
}
</style>